package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;


@ControllerAdvice
public class ExceptionCatch {
    //通用异常
    @ExceptionHandler(Exception.class)
    public ResponseResult exceptionHandler(Exception e) {


        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

    //自定义异常
    @ExceptionHandler(Exception.class)
    public ResponseResult customException(Exception e) {
        if (e instanceof CustomException){
            ((CustomException)e).getResponseResult();
        }


        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

}
